const Router = require('koa-router')
const ApiRes = require('../../lib/utils/api-res')
const router = new Router({ prefix: '/authorization' })
const AuthenticationController = require('../../controller/authentication')
const permission = require('../../middleware/permission')
const validator = require('../../middleware/validator')
const Joi = require('joi')

router.post('/assign-permission', async (ctx, next) => {
  ctx.body = { code: 200, data: '/assign-permission' }
  await next()
})

router.post(
  '/assign-routes',
  permission(),
  validator({
    domain: Joi.string(),
    roleId: Joi.string().required(),
    routeIds: Joi.string().required()
  }),
  AuthenticationController.assignRoutes
)

router.post(
  '/assign-users',
  permission(),
  validator({
    roleId: Joi.string().required(),
    userIds: Joi.string().required()
  }),
  AuthenticationController.assignUsers
)

router.get('/getUserRoutes', AuthenticationController.getUserRoutes)

module.exports = router
